package com.bank.trade_records.zhuan_money.controller;



import com.bank.trade_records.zhuan_money.entity.ZhuanMoney;
import com.bank.trade_records.zhuan_money.service.ZhuanMoneyService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
//@CrossOrigin(origins = "http://localhost:8081") // 允许来自该源的请求
@RequestMapping("/tradeRecords/ZhuanMoney")
public class ZhuanMoneyController {

    @Autowired
    private ZhuanMoneyService zhuanMoneyService;

    // 获取单个用户
    @GetMapping("/{id}")
    public ZhuanMoney getZhuanMoneyById(@PathVariable Long id) {
        return zhuanMoneyService.getZhuanMoneyById(id);
    }

    // 添加用户
    @PostMapping
    public boolean addZhuanMoney(@RequestBody ZhuanMoney zhuanMoney) {
        return zhuanMoneyService.addZhuanMoney(zhuanMoney);
    }

    // 更新用户
    @PutMapping("/{id}")
    public boolean updateZhuanMoney(@PathVariable Long id, @RequestBody ZhuanMoney zhuanMoney) {
        zhuanMoney.setId(id); // 假设前端传来的ZhuanMoney对象不包含ID，需要手动设置
        return zhuanMoneyService.updateZhuanMoney(zhuanMoney);
    }

    // 删除用户
    @DeleteMapping("/{id}")
    public boolean deleteZhuanMoneyById(@PathVariable Long id) {
        return zhuanMoneyService.deleteZhuanMoneyById(id);
    }

    // 获取所有用户
    @GetMapping
    public List<ZhuanMoney> getAllZhuanMoneys() {
        return zhuanMoneyService.getAllZhuanMoneys();
    }

    // 批量插入用户
    @PostMapping("/batch")
    public boolean batchInsert(@RequestBody List<ZhuanMoney> zhuanMoneyList) {
        return zhuanMoneyService.batchInsert(zhuanMoneyList);
    }

    @GetMapping("/page")
    public Page<ZhuanMoney> getZhuanMoneyPage(@RequestParam(value = "page", defaultValue = "1") int page,
                                        @RequestParam(value = "size", defaultValue = "10") int size) {
        Page<ZhuanMoney> zhuanMoneyPage = new Page<>(page, size);
        return zhuanMoneyService.getZhuanMoneyPage(zhuanMoneyPage);
    }
    @PostMapping("/sum")
    public List< Object> getDailyTransactionAmounts(){
        return zhuanMoneyService.getDailyTransactionAmounts();
    };

    // 其他接口...
}
